/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.oea.hibernate.entities;

import com.oea.hibernate.utilities.HibernateUtil;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import org.hibernate.Query;
import org.hibernate.Session;

/**
 *
 * @author unnati
 */
@Table(name = "branches_subjects")
@Entity
public class Branch_Subject extends AbstractEntity {

    @GeneratedValue

    @Column(name = "id")
    @Id
    protected Long id;

    @Column(name = "bid")
    protected Long bid;

    @Transient
    protected Branch branch;

    @Column(name = "subid")
    protected Long subid;

    @Transient
    protected Subject subject;

    @Column(name = "semester")
    protected int semester;

    @Transient
    protected int lecturesperweek;

    @Transient
    protected int labsperweek;

    public int getLecturesperweek() {
        return lecturesperweek;
    }

    public void setLecturesperweek(int lecturesperweek) {
        this.lecturesperweek = lecturesperweek;
    }

    public int getLabsperweek() {
        return labsperweek;
    }

    public void setLabsperweek(int labsperweek) {
        this.labsperweek = labsperweek;
    }

    public Branch getBranch() {
        return branch;
    }

    public void setBranch() {
        this.branch = (Branch) new Branch().getById(bid);
    }

    public Subject getSubject() {
        return subject;
    }

    public void setSubject() {
        this.subject = (Subject) new Subject().getById(subid);
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Long getBid() {
        return bid;
    }

    public void setBid(Long bid) {
        this.bid = bid;
    }

    public Long getSubid() {
        return subid;
    }

    public void setSubid(Long subid) {
        this.subid = subid;
    }

    public int getSemester() {
        return semester;
    }

    public void setSemester(int semester) {
        this.semester = semester;
    }
    
    public static List<Branch_Subject> getSubjectForSemesterAndBranchId(Long brid, int semester) {
        List<Branch_Subject> li = null;
        try {
            Session s = HibernateUtil.getSessionFactory().openSession();

            System.out.println("sql = from Branch_Subject where bid=" + brid + " AND semester=" + semester);
            Query q = s.createQuery("from Branch_Subject where bid=" + brid + "AND semester=" + semester);

            li = q.list();
            System.out.println("Subject Arr Sizee=" + li.size());

        } catch (Exception e) {
            e.printStackTrace();
        }
        return li;
    }

    
}
